package com.igeek.domain;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jerryHe
 * @create 2019-10-08 10:01
 * 泛型的主要作用就是通用
 *
 * limit offset,length   0 ,10,20
 */
public class Pagination<T> {
    //封装数据
    private List<T> data = new ArrayList<>();
    //每页大小
    private int pageSize;
    //当前页  offset = offset+page*pageSize
    private int page;
    //考虑最后一页  100/10=10   101/10=10...1 11
    //总记录条数
    private int count;
    //总页数
    private int totalPage;
    //分页条
    private int[] bar;


    public Pagination() {
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }


    public int[] getBar() {
        return bar;
    }

    public void setBar() {
        //分页条数组中的起始数字
        int start = 0;
        int end = 0;
        //判断总页数
        if(totalPage <=10){
            start = 1;
            end = totalPage;
        }else{
            if(page <=5){
                start = 1;
                end = 10;
            }else{
                start = page - 5;
                if(page+4 < totalPage){

                    end = page + 4;
                }else{
                    end = totalPage;
                    start = end - 9;

                }

            }
        }

        //放入所有的页数
        bar = new int[end-start+1];
        for(int i = 0;i<= end-start;i++){
            this.bar[i] = start+i;
        }
    }
}
